package br.edu.unipampa.util;

import org.andengine.engine.Engine;
import org.andengine.ui.IGameInterface.OnCreateSceneCallback;

import br.edu.unipampa.view.Menu;
import br.edu.unipampa.view.SplashScreen;

public class SceneManager {
		private BaseScene splashScene;
		private BaseScene menuScene;
		private BaseScene gameScene;
		private BaseScene criaPartidaScene;
		private BaseScene conectaPartidaScene;
		private BaseScene resultado;
		
		public static final SceneManager INSTANCE = new SceneManager();
		private SceneType currentSceneType = SceneType.SCENE_SPLASH;
	    private BaseScene currentScene;
	    private Engine engine = ResourcesManager.getInstance().engine;
		
	    public void createMenuScene()
	    {
	        ResourcesManager.getInstance().loadResourcesMenu();
	        menuScene = new Menu();
	        setScene(menuScene);
	        disposeSplashScene();
	    }
	    
	    public void createSplashScene(OnCreateSceneCallback pOnCreateSceneCallback)
	    {
	        ResourcesManager.getInstance().loadSplashScreen();
	        splashScene = new SplashScreen();
	        currentScene = splashScene;
	        pOnCreateSceneCallback.onCreateSceneFinished(splashScene);
	    }
	    
	    private void disposeSplashScene()
	    {
	        ResourcesManager.getInstance().unloadSplashScreen();
	        splashScene.disposeScene();
	        splashScene = null;
	    }
		
		public void setScene(BaseScene scene){
			engine.setScene(scene);
			currentScene = scene;
			currentSceneType = scene.getSceneType();
		}
		
		public void setScene(SceneType sceneType){
			switch (sceneType) {
			case SCENE_SPLASH:
				setScene(splashScene);
				break;
			case SCENE_MENU:
				setScene(menuScene);
				break;
			case SCENE_GAME:
				setScene(gameScene);
				break;
			case SCENE_CRIAR_PARTIDA:
				setScene(criaPartidaScene);
				break;
			case SCENE_CONECTAR_PARTIDA:
				setScene(conectaPartidaScene);
				break;
			case SCENE_RESULTADO:
				setScene(resultado);
				break; 
			default:
				break;
			}
		}
		
		public static SceneManager getInstance(){
			return INSTANCE;
		}
		
		public SceneType getCurrentSceneType(){
			return currentSceneType;
		}
		
		public BaseScene getCurreScene(){
			return currentScene;
		}
		
		public enum SceneType{
			SCENE_SPLASH,
			SCENE_MENU,
			SCENE_GAME,
			SCENE_CRIAR_PARTIDA,
			SCENE_CONECTAR_PARTIDA,
			SCENE_RESULTADO;
		}
		
		
}
